﻿using System;
using System.Collections.Generic;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

namespace DatabaseGroup.UnitTests.SSIS.SourceAdapters
{
    /// <summary>
    /// Implements dummy IDTSOutputColumnCollection90 functionality to aid testing
    /// </summary>
    public class OutputColumnCollectionTestImpl : IDTSOutputColumnCollection90
    {
        private List<IDTSOutputColumn90> _outputColumns = new List<IDTSOutputColumn90>();

        #region IDTSOutputColumnCollection90 Members

        public int Count
        {
            get { return _outputColumns.Count; }
        }

        public IDTSOutputColumn90 FindObjectByID(int lID)
        {
            throw new NotImplementedException();
        }

        public int FindObjectIndexByID(int lID)
        {
            throw new NotImplementedException();
        }

        public System.Collections.IEnumerator GetEnumerator()
        {
            return _outputColumns.GetEnumerator(); ;
        }

        public IDTSOutputColumn90 GetObjectByID(int lID)
        {
            throw new NotImplementedException();
        }

        public int GetObjectIndexByID(int lID)
        {
            throw new NotImplementedException();
        }

        public IDTSOutputColumn90 GetOutputColumnByLineageID(int lLineageID)
        {
            throw new NotImplementedException();
        }

        public IDTSOutputColumn90 New()
        {
            IDTSOutputColumn90 outputColumn = new OutputColumnTestImpl();
            _outputColumns.Add(outputColumn);

            return outputColumn;
        }

        public IDTSOutputColumn90 NewAt(int lIndex)
        {
            IDTSOutputColumn90 outputColumn = new OutputColumnTestImpl();
            _outputColumns.Insert(lIndex, outputColumn);

            return outputColumn;
        }

        public void RemoveAll()
        {
            _outputColumns.Clear();
        }

        public void RemoveObjectByID(int lID)
        {
            throw new NotImplementedException();
        }

        public void RemoveObjectByIndex(object Index)
        {
            throw new NotImplementedException();
        }

        public void SetIndex(int lOldIndex, int lNewIndex)
        {
            throw new NotImplementedException();
        }

        public IDTSOutputColumn90 this[object Index]
        {
            get 
            {
                if (Index is int)
                {
                    return _outputColumns[(int)Index];
                }
                else if (Index is string)
                {
                    foreach (IDTSOutputColumn90 outputColumn in this._outputColumns)
                    {
                        if (outputColumn.Name == (string)Index)
                        {
                            return outputColumn;
                        }
                    }
                    return null;
                }
                else
                {
                    return null;
                }
            }
        }

        #endregion
    }
}
